import qualified Data.ByteString.Short as S
#if defined(mingw32_HOST_OS)
import GHC.IO (unsafePerformIO)
+import System.OsString.Encoding.Internal (cWcharsToChars_UCS2)
+import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
#endif
toOsPath :: RawFilePath -> OsPath
fromOsPath :: OsPath -> RawFilePath
#if defined(mingw32_HOST_OS)
-fromOsPath = S.fromShort . getWindowsString . getOsString
+-- On Windows, OsString contains a ShortByteString that is
+-- utf-16 encoded. So have to convert the input from that.
+-- This is relatively expensive.
+fromOsPath = toRawFilePath . cWcharsToChars_UCS2 . BS16.unpack . getWindowsString
#else
fromOsPath = S.fromShort . getPosixString . getOsString
#endif